package com.higgins.lawapp.client.settings.components;

import java.util.List;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.HTMLTable.RowFormatter;
import com.higgins.lawapp.client.settings.dataItemModel.DataItemDTO;
import com.higgins.lawapp.client.settings.dataItemModel.DataItemLevelDTO;
import com.higgins.lawapp.client.settings.model.DataSourceModel;

public class DataItemTable extends LayoutPanel	{
	private FlexTable flexTable = new FlexTable();
	private DataSourceModel dataSourceModel;
	
	public DataItemTable(DataSourceModel dataSourceModel)	{
		this.dataSourceModel = dataSourceModel;

	}
	
	public void addData(List<DataItemDTO> dataItemDTO)	{
	    flexTable.setCellPadding(1);
	    flexTable.setCellSpacing(0);
	    flexTable.setWidth("630px");
		RowFormatter rf = flexTable.getRowFormatter();
		rf.setStyleName(0, "FlexTable-HeaderRow");
		flexTable.setText(0,0,"Data Item One");
		flexTable.setText(0,1,"Data Item Two");
		flexTable.getCellFormatter().addStyleName(0, 0,"FlexTable-normCell");
		flexTable.getCellFormatter().addStyleName(0, 1,"FlexTable-normCell");
		if (dataItemDTO!=null)	{
			List<DataItemDTO> dataItemsDTO = dataItemDTO;
			if (dataItemsDTO!=null)	{
			    int i = dataItemsDTO.size();
				int j = 0;
				while(j< i)	{
					flexTable.setText(j+1, 0, dataItemDTO.get(j).getItemOne());
					if (j < dataItemDTO.size())
						flexTable.setText(j+1, 1, dataItemDTO.get(j).getItemTwo());	
					else
						flexTable.setText(j+1, 1, "BLANK");	
					flexTable.getCellFormatter().addStyleName(j+1, 0,"FlexTable-normCell");
					flexTable.getCellFormatter().addStyleName(j+1, 1,"FlexTable-normCell");
			  	    j++;
				}		
			}
		}
	    add(flexTable);
	    setWidgetLeftWidth(flexTable, 0, Unit.PCT, 100, Unit.PCT);
	}
}
